
AC_DEFUN([AC_CHECK_POSTGRES], [
# check for postgres

AC_MSG_CHECKING([how to link postgres])
if test ".${POSTGRES_ROOT}" != . ; then
   POSTGRES_ROOT=`cd ${POSTGRES_ROOT} && pwd`
   LIBS="${LIBS} -L$POSTGRES_ROOT/lib -lecpg -lpq"
   INCLUDES="${INCLUDES} -I$POSTGRES_ROOT/include"
else
	for i in /usr/bin /usr/local/bin /usr/local/postgres/bin ; do
		if test -f "$i/pg_config" ; then
			POSTGRES_CONFIG="$i/pg_config"
		fi
	done
	if test "$POSTGRES_CONFIG" = "" ; then
		AC_MSG_ERROR(["could not find pg_config"])
	else
		AC_MSG_RESULT([config reporting tool is $POSTGRES_CONFIG])
		LIBS="${LIBS} -L`$POSTGRES_CONFIG --libdir` -lecpg -lpq"
		INCLUDES="${INCLUDES} -I`$POSTGRES_CONFIG --includedir`"
    fi
	POSTGRES_BINDIR=`$POSTGRES_CONFIG --bindir`
	AC_MSG_CHECKING([how to find ecpg])
	for ii in $POSTGRES_BINDIR /usr/bin ; do
		if test  -x $ii/ecpg ; then
			ECPG=$ii
			AC_MSG_RESULT([ ecpg is $ii/ecpg])
			break
		fi
	done
	if test x$ECPG = x; then
		AC_MSG_ERROR(["could not find ecpg - need to install libecpg-dev for debian or postgress embedded SQL dev"])
	fi
fi
])
